//
//  ForgetPass.m
//  FruitVIP
//
//  Created by 孙艳玲 on 15/6/11.
//  Copyright (c) 2015年 孙艳玲. All rights reserved.
//

#import "ForgetPass.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)


@implementation ForgetPass

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self getUI];
    }
    return self ;
}

- (void)getUI
{
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT/4)];
    UIImage *image = [UIImage imageNamed:@"firstPage.png"];
    imageView.image = image;
    //    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:imageView];


    UILabel *phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, imageView.frame.origin.y + imageView.frame.size.height + 20, SCREEN_WIDTH/3, 25)];
    phoneLabel.backgroundColor = [UIColor whiteColor];
    phoneLabel.text = @"手机号";
    [self addSubview:phoneLabel];
    
    self.nameText = [[UITextField alloc] initWithFrame:CGRectMake(phoneLabel.frame.origin.x + phoneLabel.frame.size.width, phoneLabel.frame.origin.y, SCREEN_WIDTH - 20 - phoneLabel.frame.size.width, phoneLabel.frame.size.height)];
    self.nameText.backgroundColor = [UIColor whiteColor];
    self.nameText.clearsOnInsertion = YES;
    self.nameText.clearButtonMode = UITextFieldViewModeAlways;
    [self addSubview:self.nameText];
    
    UILabel *linePhone = [[UILabel alloc] initWithFrame:CGRectMake(phoneLabel.frame.origin.x, phoneLabel.frame.origin.y + phoneLabel.frame.size.height + 3, SCREEN_WIDTH - 20, 1)];
    linePhone.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];
    [self addSubview:linePhone];
    
    UILabel *passLabel = [[UILabel alloc] initWithFrame:CGRectMake(phoneLabel.frame.origin.x, linePhone.frame.origin.y + linePhone.frame.size.height + 10, phoneLabel.frame.size.width, phoneLabel.frame.size.height)];
    passLabel.backgroundColor = [UIColor whiteColor];
    passLabel.text = @"手机验证码";
    [self addSubview:passLabel];
    
    self.passText = [[UITextField alloc] initWithFrame:CGRectMake(self.nameText.frame.origin.x, passLabel.frame.origin.y, self.nameText.frame.size.width, passLabel.frame.size.height)];
    self.passText.secureTextEntry = YES;//设置密码密文输入
    [self addSubview:self.passText];
    
    UILabel *passLine = [[UILabel alloc] initWithFrame:CGRectMake(passLabel.frame.origin.x, passLabel.frame.origin.y +passLabel.frame.size.height + 3, SCREEN_WIDTH - 20, 1)];
    passLine.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];
    [self addSubview:passLine];
    
    
    
        UIButton *textButton = [UIButton buttonWithType:UIButtonTypeCustom];
        textButton.frame = CGRectMake(self.passText.frame.size.width - 110, 0, 100, self.passText.frame.size.height-5);
        textButton.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:205.0 / 255.0 blue:0 / 255.0 alpha:1];        [textButton setTitle:@"获取验证码" forState:UIControlStateNormal];
        [textButton setTitleColor:[UIColor colorWithRed:110.0 / 255.0 green:78.0 / 255.0 blue:71.0 / 255.0 alpha:1] forState:UIControlStateNormal];
        textButton.titleLabel.font = [UIFont systemFontOfSize:15];
   textButton.layer.cornerRadius = CGRectGetHeight([textButton bounds])/2;
        [textButton addTarget:self action:@selector(textButtonAction) forControlEvents:UIControlEventTouchUpInside];
        [self.passText addSubview:textButton];
        
        UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
        nextButton.frame = CGRectMake(SCREEN_WIDTH/6, self.passText.frame.origin.y + self.passText.frame.size.height + 50, 2 * SCREEN_WIDTH /3, 2 * self.passText.frame.size.height);
        nextButton.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:205.0 / 255.0 blue:0 / 255.0 alpha:1];
        [nextButton setTitle:@"确认" forState:UIControlStateNormal];
   nextButton.layer.cornerRadius = CGRectGetHeight([nextButton bounds])/2;

        [nextButton setTitleColor:[UIColor colorWithRed:110.0 / 255.0 green:78.0 / 255.0 blue:71.0 / 255.0 alpha:1] forState:UIControlStateNormal];
        nextButton.titleLabel.font = [UIFont systemFontOfSize:17];
        [nextButton addTarget:self action:@selector(nextButtonAction)forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:nextButton];


    self.nameText.delegate = self;
    self.passText.delegate = self;
}

- (void)textButtonAction
{
    NSLog(@"获取验证码");
    self.passText.text = @"123456";
}

- (void)nextButtonAction
{
    [self.againDelegate againButton];
}
//点击键盘return键触发的方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //点击return取消第一响应者
    [self.nameText resignFirstResponder];
    [self.passText resignFirstResponder];
    return YES;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
